/*
   根据链接obj的内容提示，输入一个参数，进行追加url调用，返回通用返回值
   如果idx指定，则把同一行第idx(0起始)列设为输入值
*/

function common_ret(ret)
{
	var msg;
	if(ret == 0)
		msg = "操作成功,页面不自动刷新以方便您批量";
	else if(ret == 1)
		msg = "权限不足";
	else if(ret == 2)
		msg = "操作失败或者未变更";
	else if(ret == 3)
		msg = "数据不存在";
	else
		msg =ret;
	alert(msg);
}

function input_one(obj, idx)
{
	obj = $(obj);
	var msg = "输入“" + obj.html() + "”参数";
	var val = prompt(msg);
	if(!val)
		return;
	var ret = Ajax.call(obj.attr("href") + val, '', false, 'GET', 'TEXT', false, false);
	if(ret == 0 && idx != null)
		$(obj.parent().parent().children()[1]).html(val);
	common_ret(ret);
}

/*
   提交表单
*/
function ajax_commit(obj)
{
	obj = $(obj);
	var ret = Ajax.call(obj.attr('action'), obj.serialize(), false, 'POST', 'TEXT', false, false);
	common_ret(ret);
	return ret;
}

/*
   提交当前值
 */
function ajax_value(obj, url)
{
	obj = $(obj);
	var ret = Ajax.call(url + obj.val(), '', false, 'GET', 'TEXT', false, false);
	common_ret(ret);
}

/*
   提交当前链接
 */
function ajax_this(obj)
{
	obj = $(obj);
	var href = obj.attr("href");
	if(href == "#")
	{
		alert("已操作过,刷新可继续");
		return;
	}
	var ret = Ajax.call(href, '', false, 'GET', 'TEXT', false, false);
	common_ret(ret);
	if(ret == 0)
		obj.attr("href", "#");
}

/*
   查看会员信息
 */

function showuser(id)
{
	var ret = Ajax.call('index.php?action=index.userinfo&id='+id, '', false, 'GET', 'TEXT', false, false);
	alert(ret);
	return false;
}

/*
   查看管理员信息
 */

function showadm(id)
{
	if(id == 1)
	{
		alert('系统自身');
		return;
	}
	var ret = Ajax.call('index.php?action=index.adminfo&id='+id, '', false, 'GET', 'TEXT', false, false);
	alert(ret);
	return false;
}

/*
   将表单跳转改为普通跳转，避免刷新提示
*/
function form2url(obj)
{
	var url = obj.attr('action') + '&' +  obj.serialize();
	gotoUrl(url);
}

function gotoUrl(url) {
    window.location.href=url;
}

String.prototype.len = function()           // 给string增加个len ()方法，计算string的字节数
{ 
    return this.replace(/[^\x00-\xff]/g, "xx").length; 
};

// 列表字符串截取
$(document).ready(function(){
		/*测试代码，上线之前去除*/
		var html_str = $(document.documentElement).html();
		if(html_str.indexOf('Notice') != -1)
			alert("页面有错误(Notice)，请查看源码");
		/*end*/
		$("[name='print_page']").click(function(){
			var url = window.location.href
			url = url.replace(/#*$/, "&g_ext[print]=1");
			window.location.href=url;
		});
		$("td .introduce").each(function(){
			if ($(this).text().len() > 40) {
			var val = $(this).text();
			$(this).attr("title",val);
			$(this).text(val.substring(0, 20) + '...');
			}
			});
		});

/**
 * 自动跳转
 */
function autoJump(secs, surl) {
    var jumpTo = document.getElementById('jumpTo');
    if (jumpTo) {
        jumpTo.innerHTML=secs;
    }
    if(--secs>0) {
        setTimeout("autoJump("+secs+",'"+surl+"')",1000);
    } else {
        location.href=surl;
    }
}

function search_select(id, value, formId) {
    $(id).val(value);
    $(formId).submit();
}

/**
 * 打开窗口
 * @param {type} id 页面DIV的ID
 * @param {type} url 有效的URL
 * @param {type} title 弹出窗口名称
 * @returns {undefined}
 */
function openWindow(id, url, iWidth, iHeight, title) {
    var innerDiv = document.getElementById(id);
    if (innerDiv) {
        $.jBox('id:'+id, {
            title: title,
            width: iWidth,
            height: iHeight
        });
    } else {
        $.jBox("iframe:"+url, {
            title: title,
            width: iWidth,
            height: iHeight,
            buttons: { '关闭': true }
        });
    }
}

    function changeFileInput(inputId) {
        var thisInputID = '#' + inputId;
        var thisInputVal = $(thisInputID).val();
        $(thisInputID).siblings('input').val(thisInputVal);
    }
function NoToChinese(num) {
    if (!/^\d*(\.\d*)?$/.test(num)) {
        alert("Number is wrong!");
        return "Number is wrong!";
    }
    var AA = new Array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖");
    var BB = new Array("", "拾", "佰", "仟", "萬", "億", "点", "");
    var a = ("" + num).replace(/(^0*)/g, "").split("."), k = 0, re = "";
    for (var i = a[0].length - 1; i >= 0; i--) {
        switch (k) {
            case 0:
                re = BB[7] + re;
                break;
            case 4:
                if (!new RegExp("0{4}\\d{" + (a[0].length - i - 1) + "}$").test(a[0]))
                    re = BB[4] + re;
                break;
            case 8:
                re = BB[5] + re;
                BB[7] = BB[5];
                k = 0;
                break;
        }
        if (k % 4 == 2 && a[0].charAt(i + 2) != 0 && a[0].charAt(i + 1) == 0)
            re = AA[0] + re;
        if (a[0].charAt(i) != 0)
            re = AA[a[0].charAt(i)] + BB[k % 4] + re;
        k++;
    }

    if (a.length > 1) //加上小数部分(如果有小数部分) 
    {
        re += BB[6];
        for (var i = 0; i < a[1].length; i++)
            re += AA[a[1].charAt(i)];
    }
    return re;
} 
